<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="admin/common/common_css :: commonHeader('登录')">
</head>
<link th:href="@{/js/admin.ui/static/h-ui.admin/css/H-ui.login.css}" rel="stylesheet" type="text/css" />
<!--<body onload="javascript: shiro.ajax({url: '/heartbeat.action'});">-->
<body>
<div class="header"></div>
<div class="loginWraper">
    <div id="loginform" class="loginBox">
        <form class="form form-horizontal" id="form-user-login" method="post" onsubmit="return executeLogin();">
            <div class="row cl">
                <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60d;</i></label>
                <div class="formControls col-xs-8">
                    <input name="account" id="account" type="text" placeholder="账号" class="input-text size-L" />
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60e;</i></label>
                <div class="formControls col-xs-8">
                    <input name="password" id="password" type="password" placeholder="密码" class="input-text size-L" />
                </div>
            </div>
            <div class="row cl">
                <div class="formControls col-xs-8 col-xs-offset-3">
                    <input class="input-text size-L" id="captcha" name="captcha" type="text" placeholder="验证码" style="width:150px;" />
                    <img id="captchaImg" src="/pestdiagnosis/captcha" width="100" height="40" />
                    <a href="javascript:reloadCaptcha();" style="text-decoration: none;">看不清，换一张</a>
                </div>
            </div>
            <div class="row cl" style="display: none;">
                <div class="formControls col-xs-8 col-xs-offset-3">
                    <label for="online">
                        <input type="checkbox" name="rememberMe" id="rememberMe" value="rememberMe" />
                        使我保持登录状态
                    </label>
                </div>
            </div>
            <div class="row cl">
                <div class="formControls col-xs-8 col-xs-offset-3">
                    <input type="submit" class="btn btn-success radius size-L" value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;" />
                    <input type="reset" class="btn btn-default radius size-L" value="&nbsp;取&nbsp;&nbsp;&nbsp;&nbsp;消&nbsp;" />
                </div>
            </div>
        </form>
    </div>
</div>
<div th:include="admin/common/common_js :: onLoadJS"></div>
<script type="text/javascript">
    // 执行登录
    function executeLogin() {
        var account = $.trim($('#account').val());
        var password = $.trim($('#password').val());
        var captcah = $.trim($('#captcha').val());
        if(shiro.util.isEmpty(account)) {
            layer.tips('账号不能为空', '#account');
            return false;
        } else if(shiro.util.isEmpty(password)) {
            layer.tips('密码不能为空', '#password');
            return false;
        } else if(shiro.util.isEmpty(captcah)) {
            layer.tips('验证码不能为空', '#captcha');
            return false;
        } else {
            send('/pestdiagnosis/executeLogin',
                $('#form-user-login').serialize(),
                function (data) {
                    if(data.result == 0) {
                        layer.msg(data.message);
                        window.location.href = '/pestdiagnosis/main';
                    } else {
                        layer.msg(data.message, {icon: 5,time: 1500});
                        $('#account').focus();
                    }
                },
                function(res){
                    layer.msg(data.message, {icon: 5,time: 1500});
                    $('#account').focus();
                }
                )
//            shiro.ajax({
//                url: '/pestdiagnosis/executeLogin',
//                data:$('#form-user-login').serialize(),
//                success: function(data) {
//                    if(data.result == 0) {
//                        layer.msg(data.message);
//                        window.location.href = '/pestdiagnosis/main.';
//                    } else {
//                        layer.msg(data.message, {icon: 5,time: 1500});
//                        $('#account').focus();
//                    }
//                }
//            });
        }
        return false;
    }
    // 刷新验证码
    function reloadCaptcha() {
        $('#captchaImg').attr('src', '/pestdiagnosis/captcha?date=' + new Date());
    }
</script>
</body>
</html>